package routines

import (
	"ntrace/utils/panics"
	"ntrace/utils/traces"
	"time"
)

func GoWithRecover(name string, f func()) {
	go func() {
		defer panics.Recover(name)
		f()
	}()
}

func GoWithTimeTrack(name string, f func()) {
	go func() {
		defer traces.TrackTime(name, time.Now())
		f()
	}()
}

func GoWithRecoverWithTimeTrack(name string, f func()) {
	go func() {
		defer panics.Recover(name)
		defer traces.TrackTime(name, time.Now())
		f()
	}()
}

func WrapWithRecover(name string, f func()) func() {
	return func() {
		defer panics.Recover(name)
		f()
	}
}

func WrapWithTimeTrack(name string, f func()) func() {
	return func() {
		defer traces.TrackTime(name, time.Now())
		f()
	}
}

func WrapWithRecoverWithTimeTrack(name string, f func()) func() {
	return func() {
		defer panics.Recover(name)
		defer traces.TrackTime(name, time.Now())
		f()
	}
}
